| Conditions | 1 |
| Paths | 16 |
| Total Lines | 55 |
| Lines | 55 |
| Ratio | 100 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /* TODO |
||
| 169 | access.login(req.query.id, req.query.pwd, res, function (headers, ires) {
|
||
| 170 | fullLog && console.log((timeStamp() + 'Successfully logged in.').green); |
||
|
1 ignored issue
–
show
|
|||
| 171 | |||
| 172 | var ret = {};
|
||
| 173 | var $ = cheerio.load(ires.text); |
||
| 174 | |||
| 175 | ret.name = escaper.unescape($('.block1text').html()).match(/姓名:.+</)[0].replace('<', '').substring(3);
|
||
| 176 | ret.id = req.query.id; |
||
| 177 | ret.sem = req.query.sem || getSem(); |
||
| 178 | |||
| 179 | superagent |
||
| 180 | .post('http://csujwc.its.csu.edu.cn/jsxsd/xsks/xsksap_list')
|
||
| 181 | .set(headers) |
||
| 182 | .type('form')
|
||
| 183 | .send({
|
||
| 184 | xqlbmc: '', |
||
| 185 | xnxqid: ret.sem, |
||
| 186 | xqlb: '' |
||
| 187 | }) |
||
| 188 | .end(function (err, iires) {
|
||
| 189 | if (err) {
|
||
| 190 | console.log((timeStamp() + 'Failed to reach exams page\n' + err.stack).red); |
||
|
1 ignored issue
–
show
|
|||
| 191 | res.send({ error: '获取成绩失败' });
|
||
| 192 | return next(err); |
||
| 193 | } |
||
| 194 | fullLog && console.log((timeStamp() + 'Successfully entered exams page.').green); |
||
| 195 | |||
| 196 | $ = cheerio.load(iires.text); |
||
| 197 | |||
| 198 | ret.exams = {};
|
||
| 199 | ret['exams-count'] = 0; |
||
| 200 | |||
| 201 | $('#dataList tr').each(function (index) {
|
||
| 202 | if (index === 0) {
|
||
| 203 | return; |
||
| 204 | } |
||
| 205 | let element = $(this).find('td');
|
||
| 206 | let title = escaper.unescape(element.eq(3).text()); |
||
| 207 | |||
| 208 | let item = {
|
||
| 209 | time: escaper.unescape(element.eq(4).text()), |
||
| 210 | location: escaper.unescape(element.eq(5).text()), |
||
| 211 | seat: escaper.unescape(element.eq(6).text()) |
||
| 212 | }; |
||
| 213 | |||
| 214 | ret.exams[title] = item; |
||
| 215 | ret['exams-count']++; |
||
| 216 | }); |
||
| 217 | |||
| 218 | access.logout(headers, res, function() {
|
||
| 219 | res.send(JSON.stringify(ret)); |
||
| 220 | fullLog && console.log((timeStamp() + 'Successfully logged out: ').green + req.query.id.yellow + (' (processed in ' + (new Date() - start) + 'ms)').green);
|
||
|
1 ignored issue
–
show
|
|||
| 221 | }); |
||
| 222 | }); |
||
| 223 | }); |
||
| 224 | }); |
||
| 232 |